/*审核预算 */
<template>
  <div>
    <div v-if="indexKey === 1">
      <condition-card @reset="resetSearch" @search="onSearch" label-position="right" label-width="170px">
        <el-row :gutter="24" style="height: 50px;">
          <el-col :span="8">
            <el-form-item :label="$t('collegeFirstTrial.year')">
              <el-date-picker style="width:100%" :clearable="false"
                v-model="queryForm.condition.year"
                type="year" value-format="yyyy" format="yyyy">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('projectDeclara.competiProject')">
              <el-input v-model.trim="queryForm.condition.name" style="width:100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('projectDeclara.competiLevel')">
              <el-select v-model="queryForm.condition.comLevel" clearable style="width:100%">
                <el-option
                  v-for="item in options.degreeType"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('graduate.college')">
                <DictSelect v-model="queryForm.condition.college" filterable :data="options.faculty" :plzSelect="true"></DictSelect>
              </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('projectDeclara.competition')">
              <el-select v-model="queryForm.condition.typeId" clearable filterable style="width:100%">
                <el-option
                  v-for="item in options.country"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('projectDeclara.competiStatus')">
              <el-select v-model="queryForm.condition.status" clearable style="width:100%">
                <el-option
                  v-for="item in options.status"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </condition-card>
      <el-card shadow="never" v-loading="loading" body-style="padding: 24px;" class="card-margin">
        <h1 class="condition-title">{{$t('approveBudget.auditedBudgetList')}}</h1>
        <el-row type="flex" class="row-bg" justify="space-between" style="margin-bottom:10px">
          <div class="float-left" style="display: flex;margin-top: 10px;">
            <span style="margin-left:10px;font-size: 18px;color:#303133;">{{$t('approveBudget.amountApplied')}}：{{applySum}}(元)</span>
            <span style="margin-left:20px;font-size: 18px;color:#303133;">{{$t('approveBudget.budgetLimit')}}：{{annualBudget}}(元)</span>
            <span style="margin-left:20px;font-size: 18px;color:#303133;">{{$t('approveBudget.currentCategory')}}：{{availableBudget}}(元)</span>
            <span style="margin-left:20px;font-size: 18px;color:#303133;">{{$t('approveBudget.reviewedBudgetStastic')}}：{{usedBudget}}(元)</span>
          </div>
          <div class="float-right" style="display: flex;">
              <el-button style="margin-left:10px" type="primary" @click="sorting">{{$t('approveBudget.sorting')}}</el-button>
              <el-button style="margin-left:10px" type="primary" @click="exportFile">{{$t('internship.derive')}}</el-button>
          </div>
        </el-row>
        <edu-table :pagination="false"  :order='false' :tooltipEffect="tooltipEffect" stripe :data="dataList" size="mini" @selection-change="handleSelectionChange">
          <edu-table-column :label="$t('collegeFirstTrial.year')" fixed prop="year" > </edu-table-column>
          <edu-table-column :label="$t('graduate.college')" fixed prop="collegeName"></edu-table-column>
          <edu-table-column :label="$t('projectScore.competiProject')" fixed prop="name" width="130px">
             <template slot-scope="scope">
              <el-button style="font-size: 15px;" type="text" @click="approveGetEdit(scope.row, '查看')">{{scope.row.name}}</el-button>
            </template>
          </edu-table-column>
          <edu-table-column :label="$t('projectScore.competiLevel')" fixed prop="comLevelName" > </edu-table-column>
          <edu-table-column :label="$t('approveBudget.competition')" fixed prop="typeName" width="120px"></edu-table-column>
          <edu-table-column :label="$t('projectDeclara.applicant')" fixed prop="creator" width="120px"> </edu-table-column>
          <edu-table-column :label="$t('approveBudget.qualifica')" prop="lastPlanBudget" width="120px"> </edu-table-column>
          <edu-table-column :label="$t('approveBudget.sites')" prop="comPlace" > </edu-table-column>
          <edu-table-column :label="$t('approveBudget.entrants')" prop="peopleNumber" width="120px"> </edu-table-column>
          <edu-table-column :label="$t('approveBudget.capita')" prop="average" width="110px"></edu-table-column>
          <edu-table-column :label="$t('approveBudget.expenditure')" prop="budgetOneOne" > </edu-table-column>
          <edu-table-column :label="$t('approveBudget.serviceFee')" prop="budgetOneTwo" width="130px"> </edu-table-column>
          <edu-table-column :label="$t('approveBudget.studentFee')" prop="budgetOneThree" > </edu-table-column>
          <edu-table-column :label="$t('approveBudget.equipment')" prop="budgetTwoOne" width="120px"> </edu-table-column>
          <edu-table-column :label="$t('approveBudget.purchaseCost')" prop="budgetTwoTwo" width="170px"> </edu-table-column>
          <edu-table-column :label="$t('approveBudget.materialsFee')" prop="budgetTwoThree" width="120px"> </edu-table-column>
          <edu-table-column :label="$t('approveBudget.international')" prop="budgetThreeOne" width="170px"> </edu-table-column>
          <edu-table-column :label="$t('approveBudget.literature')" prop="budgetThreeTwo" width="240px"> </edu-table-column>
          <edu-table-column :label="$t('approveBudget.rentalFee')" prop="budgetThreeThree"> </edu-table-column>
          <edu-table-column :label="$t('approveBudget.processing')" prop="budgetThreeFour" width="150px"> </edu-table-column>
          <edu-table-column :label="$t('approveBudget.specialOperat')" prop="budgetThreeFive" width="120px"> </edu-table-column>
          <edu-table-column :label="$t('approveBudget.summation')" prop="applySum"> </edu-table-column>
          <edu-table-column :label="$t('approveBudget.auditedBudget')" prop="approvedBudget" width="120px"> </edu-table-column>
          <edu-table-column :label="$t('projectDeclara.competiStatus')" prop="status">
            <template slot-scope="scope">
                <el-button v-if="scope.row.status ==1" type="info" plain>申报中</el-button>
                <el-button v-else-if="scope.row.status ==2" type="info" plain>已驳回</el-button>
                <el-button v-else-if="scope.row.status ==3" type="info" plain>立项中</el-button>
                <el-button v-else-if="scope.row.status ==4" type="info" plain>未立项</el-button>
                <el-button v-else-if="scope.row.status ==5" type="success" plain>已立项</el-button>
                <el-button v-else-if="scope.row.status ==6" type="danger" plain>项目结束</el-button>
            </template>
          </edu-table-column>
          <edu-table-column :label="$t('common.text.operation')" fixed="right" fit prop="operate" width="180px">
            <template slot-scope="scope">
              <el-button v-if='scope.row.currentFlow==10||scope.row.currentFlow==11||scope.row.currentFlow==12' type="text" @click="approveGet(scope.row, '编辑')">{{$t('approveBudget.approveBudget')}}</el-button>
              <el-button v-if='scope.row.currentFlow==12' type="text" @click="selectEvalExamine(scope.row,'projectApproval')">{{$t('approveBudget.projectApproval')}}</el-button>
              <el-button v-if='scope.row.currentFlow==12' type="text" @click="selectEvalExamine(scope.row,'refusedProject')">{{$t('approveBudget.refusedProject')}}</el-button>
              <el-button v-if='scope.row.status == 5' type="text" @click="adjustBudget(scope.row)">{{$t('approveBudget.adjustBudget')}}</el-button>
            </template>
          </edu-table-column>
          
        </edu-table>
        <el-row type="flex" class="row-bg" justify="end">
          <el-col>
              <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="queryForm.pageNum_"
                :page-sizes="[20, 40, 80, 100]"
                :page-size="queryForm.pageSize_"
                layout="total, sizes, prev, pager, next, jumper"
                :total="queryForm.total_"
                style="float:right;margin-top:10px"
              ></el-pagination>
          </el-col>
        </el-row>
      </el-card>
      <edu-export-dialog
        :disabled="exportButton"
        :title="$t('message.prompt')"
        ref="downloadRef"
        :data="exportResult">
      </edu-export-dialog>
    </div>
    <!-- 新增 -->
    <div v-if="indexKey === 2">
      <projectDeclarationEdit @change-exam='changeExam' ref="addFinom" @change-add='changeAdd' :compile='compile' :dataList='dataListObj'></projectDeclarationEdit>
    </div>
    <!-- 编辑/查看 -->
    <div v-if="indexKey === 3">
      <list-interdiEdit @change-exam='changeExam' :compile='compile' :ojbData='ojbData' :dataList='dataListObj'></list-interdiEdit>
    </div>
    <!-- 调整预算开始 -->
    <el-dialog
      :title="$t('approveBudget.adjustBudget')"
      width="30%"
      :before-close="cancel"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false">
      <el-form :model="dialogForm" label-position="right" ref="dialogForm" label-width="120px">
        <el-row>
          <el-col :span="24">
            <el-form-item
              :label="$t('approveBudget.theBudget') + '：'"
              prop="theBudget"
              :rules="[{ required: true, message: $t('approveBudget.requireTheBudget'), trigger: 'blur' }, { validator: checkTheBudget, trigger: 'blur'}]">
              <el-input v-model.trim="dialogForm.theBudget" clearable></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <template>
          <el-button @click="cancel('dialogForm')">{{$t('common.btn.cancel')}}</el-button>
          <el-button type="primary" @click="confirm('dialogForm')">{{$t('common.btn.confirm')}}</el-button>
        </template>
      </span>
    </el-dialog>
    <!-- 调整预算结束 -->
  </div>
</template>
<script>
import { queryDic } from "common/src/api/dictionary";
import UTILS from "common/src/utils/utils";
import competiManagementApi from 'common/src/api/subjectCompetition/competiManagement';
import projectApplicaApi from 'common/src/api/subjectCompetition/projectApplica';
import subjectCompetitionApi from 'common/src/api/subjectCompetition/subjectCompetition';
import store from 'common/src/store';
import projectDeclarationEdit from 'common/src/views/competiManagement/projectDeclaration/projectDeclarationEdit';
import interdiEdit from 'common/src/views/competiManagement/auditBudget/auditBudgetEdit';
// import submitAssignment from './submitAssignment';
export default {
  components: {
    projectDeclarationEdit,
    'list-interdiEdit': interdiEdit
    // 'list-submitAssignment': submitAssignment
  },
  data() {
    return {
      fileList: [],
      indexKey: 1,
      compile: '',
      dataListObj: {},
      ojbData: {},
      formList: new FormData(),
      dataFormList: {}, //接收路由跳转的数据
      dataForm: {
        
      }, //表格数据
      internship: {
        opinion: ''
      },
      queryFormRmport: {
        calendarId: '',
        enclosureFileName: '',
        enclosureFileUrl: '',
        calendarName: ''
      },
      queryFormRmportId: '',
      queryCalendarName: '',
      dataList: [],
      exportButton: false,
      listRmportVisible: false,
      englishScoreManage: {
        cet4ScoreExcellent: ''
      },
      tableList: [],
      tableScoreList: [],
      options: {
        faculty: [],
        status: [
          { label: '申报中', value: 1},
          { label: '已驳回', value: 2},
          { label: '立项中', value: 3},
          { label: '未立项', value: 4},
          { label: '已立项', value: 5},
          { label: '项目结束', value: 6}
        ],
        degreeType: [],
        country: [],
        comPlace: []
      },
      dialogVisible: false,
      dialogForm: {
        theBudget: ''
      },
      outsideAdvisorId: '',
      curCheckStandard: '',
      curPracticeId: '',
      queryForm: {
        condition: {
          year: new Date().getFullYear()+'',
          name: '',
          typeId: '',
          comLevel: '',
          college: '',
          status: '',
          defaultOrder: 1,
        },
        pageNum_: 1,
        pageSize_: 20,
        total_: 0,
      },
      applySum: 0,
      annualBudget: 0,
      availableBudget: 0,
      usedBudget: 0,
      loading: false,
      calendarName: '',
      useConfigParamList: '',
      useConfigParam: '',
      restaurants: [],
      semester: [],
      semesterRmpor: [],
      multipleSelection: [],
      tableData: []
    };
  },
  filters: {
    collegeAcademyList(val, array) {
      let str = "";
      for (let item of array) {
        if (val === item.value) {
          str = item.label;
        }
      }
      return str;
    }
  },
  created() {
    let data = {
        pageNum_: 1,
        pageSize_: 999,
        total_: 0,
        condition: {
          name: ''
        }
      }
      competiManagementApi.projectcategoryListPage(data).then(res => {
        this.options.country = res.data.list
      })
  },
  mounted() {
    this.getOptions()
    this.postProjectApplicaApi(this.queryForm)
    this.getStatistic(this.queryForm.condition)
  },
   methods: {
    postProjectApplicaApi(data) {
      projectApplicaApi.getApproveBudgetPage(data).then(res => {
        this.dataList = res.data.list
        this.queryForm.total_ = res.data.total_
      })
    },
    getStatistic(data) {
      projectApplicaApi.getApproveBudgetStatistic(data).then(res => {
        this.applySum = res.data.applySum
        this.annualBudget = res.data.annualBudget
        this.availableBudget = res.data.availableBudget
        this.usedBudget = res.data.usedBudget
      })
    },
    changeInput(data, val) {
      let expReg = /^[1-9]$|^([0-9])+(.[0-9]{1})?$/
      if (!expReg.test(val)) {
        this.$set(data, 'score', '')
        this.$message(this.$t('projectDeclara.decimalPlace'))
      } else if (!(data.upperLimit <= val) || !(val <= data.lowerLimit)) {
        this.$set(data, 'score', '')
        this.$message.warning('请检查数据是否完整')
      } 
    },
    // 校验调整预算
    checkTheBudget(rule, value, callback) {
      let regEn = /^(\d{1,11})(\.\d{0,2})?$/;
      if (!regEn.test(value)) {
        callback(new Error(this.$t('approveBudget.validateBudget')))
      } else if (Number(value) === 0 || Number(value) > 99999999999) {
        callback(new Error(this.$t('approveBudget.validateBudget')));
      } else {
        callback();
      }
    },
    // 提交任务书
    internAssignment(data) {
      projectApplicaApi.projectListgetDetail(data.id).then(res => {
        this.compile = '编辑'
        this.dataListObj = res.data
        this.indexKey = 3
      })
    },
    // 提交成果
    submitResults(data) {},
    // 重新提交
    selectEvalExamine(data,variable) {
      let obj = {
        id: data.id
      }
      obj.setUp = variable=='projectApproval'?1:0
      projectApplicaApi.getApprovedBudgetBySetUp(obj).then(res => {
        this.$message.success(this.$t('internship.successfully'));
        this.queryForm.pageNum_ = 1
        this.postProjectApplicaApi(this.queryForm)
      })
    },
    // 审核预算
    approveGet(data, val) {
      projectApplicaApi.getApprovedBudgetByProject(data.id).then(res => {
        this.compile = val
        this.dataListObj = res.data
        this.ojbData = data
        this.indexKey = 3
      })
    },
    // 调整预算
    adjustBudget(row) {
      this.dialogForm.id = row.id
      this.dialogForm.theBudget = row.approvedBudget
      this.dialogVisible = true
    },
    // 查看
    approveGetEdit(data, val) {
      projectApplicaApi.projectListgetDetail(data.id).then(res => {
        this.compile = val
        this.dataListObj = res.data
        this.ojbData = data
        this.indexKey = 2
      })
    },
    // 导出
    exportFile() {
      if (this.multipleSelection.length > 0) {
        let ids = []
        this.multipleSelection.forEach(el => {
          ids.push(el.id);
        })
        let obj = {
          ids: ids,
          projectDTO: this.queryForm.condition
        }
        projectApplicaApi.postExportexportApproveList(obj).then(res => {
          this.$message.success(this.$t('internship.successfully'));
        })
      } else {
        let obj = {
          ids: [],
          projectDTO: this.queryForm.condition
        }
        projectApplicaApi.postExportexportApproveList(obj).then(res => {
          this.$message.success(this.$t('internship.successfully'));
        })
      }
    },
    // 更新排序
    sorting() {
      this.queryForm.pageNum_ = 1
      this.queryForm.condition.defaultOrder = 2
      this.postProjectApplicaApi(this.queryForm)
      this.getStatistic(this.queryForm.condition)
    },
    // 返回列表主页
    changeExam() {
      this.indexKey = 1
      this.multipleSelection = []
      this.queryForm.pageNum_ = 1
      this.queryForm.condition.defaultOrder = 1
      this.postProjectApplicaApi(this.queryForm)
      this.getStatistic(this.queryForm.condition)
    },
    
    // 导入
    exportLead() {
      // this.getSchoolCalendar();
      this.queryFormRmport.calendarId = this.queryFormRmportId
      this.listRmportVisible = true;
    },
    // 勾选
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    
    getOptions() {
      // 筛选条件字典查询
      let data = {
        lang: this.$store.getters.language || "cn",
        type: "allChild",
        keys: ["X_YX", 'G_XBIE', "JSGL_JSJB", 'G_GJQU']
      };
      queryDic(data).then(res => {
        UTILS.fillSelect(
          {
            faculty: "X_YX",
            degreeType: "JSGL_JSJB",
            sex:"G_XBIE"
          },
          res.data,
          this.options
        );
      });
    },
    // 筛选
    onSearch() {
      this.queryForm.pageNum_ = 1
      this.queryForm.condition.defaultOrder = 1
      this.postProjectApplicaApi(this.queryForm)
      this.getStatistic(this.queryForm.condition)
    },
    // 重置
    resetSearch() {
      for (let key in this.queryForm.condition) {
        this.queryForm.condition[key] = '';
      }
      this.queryForm.condition.year = new Date().getFullYear()+''
      this.queryForm.pageNum_ = 1
      this.queryForm.condition.defaultOrder = 1
      this.postProjectApplicaApi(this.queryForm)
      this.getStatistic(this.queryForm.condition)
    },
    // 取消
    cancelRmport() {
      this.listRmportVisible = false;
    },
    handleSizeChange(val) {
      this.queryForm.pageSize_ = val
      this.queryForm.pageNum_ = 1
      this.postProjectApplicaApi(this.queryForm)
      this.getStatistic(this.queryForm.condition)
    },
    handleCurrentChange(val) {
      this.queryForm.pageNum_ = val
      this.postProjectApplicaApi(this.queryForm)
      this.getStatistic(this.queryForm.condition)
    },
    goBack() {
      this.$store.commit("delete_tabs", this.$route.path);
      this.$router.go(-1);
    },
    // 取消
    cancel() {
      this.dialogVisible = false
      this.$refs['dialogForm'].clearValidate()
    },
    // 确认
    confirm() {
      this.$refs['dialogForm'].validate((valid) => {
        if (valid) {
          let params = {
            id: this.dialogForm.id,
            approvedBudget: this.dialogForm.theBudget
          }
          projectApplicaApi.adjustTheBudget(params).then(res => {
            this.$message.success(this.$t('collegeFirstTrial.setSuccessfully'))
            this.dialogVisible = false
            this.$refs['dialogForm'].clearValidate()
            this.postProjectApplicaApi(this.queryForm)
            this.getStatistic(this.queryForm.condition)
          })
        }
      })
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
  .p_cals:hover{
    cursor: pointer;
    color: #409eff;
  }
  .p_cals{
    color: #aaa
  }
  .inner-breadcrumb {
      .breadcrumb {
          span {
              font-weight: normal;
              color: #aaa;
          }
          a {
              font-weight: normal;
              color: #aaa;
          }
          a:hover {
              color: #409eff;
          }
          .last {
              font-weight: bold !important;
              cursor: default !important;
          }
          .disable {
              cursor: default !important;
          }
      }
  }
  .condition-title-p {
      font-weight: 400;
      font-style: normal;
      color: #2b3b4e;
      font-size: 18px;
      margin-bottom: 15px;
  }
  .base-info-title {
      font-weight: 400;
      font-style: normal;
      font-size: 16px;
      color: #2b3b4e;
  }
  .table-style-baseinfo {
      background-color: rgba(210, 212, 214, 1);
      box-sizing: border-box;
      border-width: 0.5px;
      border-style: solid;
      border-color: rgba(210, 212, 214, 1);
      border-radius: 0px;
      -moz-box-shadow: none;
      -webkit-box-shadow: none;
      box-shadow: none;
      width: 100%;
      font-weight: 401;
      font-style: normal;
      font-size: 14px;
      color: #8896a7;
      margin-bottom: 20px;
  }

  .table-style-baseinfo td {
      width: 25%;
      background-color: rgba(255, 255, 255, 1);
      border: none;
      border-radius: 0px;
      -moz-box-shadow: none;
      -webkit-box-shadow: none;
      box-shadow: none;
      font-weight: 401;
      font-style: normal;
      font-size: 14px;
      color: #2b3b4e;
      height: 32px;
      padding: 0 10px;
  }

  .table-style-baseinfo .text-right-background-color {
      background-color: #fdfeff4d;
      text-align: right;
  }

  .text-left-background-none {
      text-align: left;
  }
</style>